{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Given two arrays, write a function to compute their intersection\n",
    "\n",
    "**给定2个数组，计算它们的交集**\n",
    "\n",
    "[原题 The Oringinal Question](https://mp.weixin.qq.com/s/44rBWbpPJAy3PqxV1jdedg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question（题目再现）\n",
    "\n",
    "Given two arrays, write a function to compute their intersection - the intersection means the numbers that are in both arrays.\n",
    "\n",
    "给定2个数组，编写一个函数计算它们之间的交集。其中，交集是同时存在于2个数组的元素。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example（样例）\n",
    "\n",
    "```text\n",
    "Input: nums_1 = [1, 2, 2, 1], nums_2 = [2, 2]\n",
    "Output: [2]\n",
    "```\n",
    "\n",
    "```text\n",
    "Input: nums_1 = [4, 9, 5], nums_2 = [9, 4, 9, 8, 4]\n",
    "Output: [9, 4]\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Notes（提示）\n",
    "\n",
    "- Each element in the result must be unique.\n",
    "- The result can be in any order.\n",
    "- 结果中的所有元素必须唯一。\n",
    "- 结果中元素的顺序可以是任意的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def intersection(self, nums_1: list, nums_2: list) -> list:\n",
    "        nums_1 = set(nums_1)\n",
    "        nums_2 = set(nums_2)\n",
    "        result = set.intersection(nums_1, nums_2)\n",
    "        return list(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9, 4]\n"
     ]
    }
   ],
   "source": [
    "print(Solution().intersection([4, 9, 5], [9, 4, 9, 8, 4]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
